#!/bin/sh

cd /
mkdir sugar

apt-get install libcurl4-openssl-dev libjansson-dev libssl-dev libgmp-dev -y
apt-get install wget unzip -y

cd /sugar

wget https://github.com/decryp2kanon/sugarmaker/releases/download/v2.5.0-sugar4/sugarmaker-v2.5.0-sugar4-linux64.zip
unzip /sugar/sugarmaker-v2.5.0-sugar4-linux64.zip

cat << EOF >> job.sh
pid=\`ps -ef | grep sugarmaker| grep -v grep|awk '{print $2}'\`
if [ ! \$pid ]; then
\`/sugar/run-sugar.sh \$1\`
else echo "program is running.."
fi
EOF

echo "nohup /sugar/sugarmaker-v2.5.0-sugar4-linux64/sugarmaker -a YespowerSugar -o stratum+tcp://sugar.ss.dxpool.com:3366 -u \$1 \$2 -p x &" > run-sugar.sh
chmod +x job.sh run-sugar.sh

#主机
crontab -l > conf && echo "* * * * * /sugar/job.sh $1 $2" >> conf && crontab conf && rm -f conf

echo `ps -ef | grep sugarmaker| grep -v grep|awk '{print $2}'`